{{define "system/role/edit"}}
<!DOCTYPE html>
<html lang="zh">
<head>
    {{template "header" (OssUrl)}}
    <link href="{{OssUrl}}/resource/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" rel="stylesheet"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content   ibox-content">
    <form class="form-horizontal m" id="form-role-edit">
        <input id="roleId" name="roleId" type="hidden" value="{{.role.RoleId}}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">角色名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="roleName" id="roleName" value="{{.role.RoleName}}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">权限字符：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="roleKey" id="roleKey" value="{{.role.RoleKey}}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">显示顺序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="roleSort" id="roleSort" value="{{.role.RoleSort}}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <label class="toggle-switch switch-solid">
                    <input type="checkbox" id="status" {{if eq .role.Status "0"}}checked{{end}}>
                    <span></span>
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input id="remark" name="remark" class="form-control" type="text" value="{{.role.Remark}}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单权限</label>
            <div class="col-sm-8">
                <div id="menuTrees" class="ztree"></div>
            </div>
        </div>
    </form>
</div>
{{template "footer" (OssUrl)}}
<script src="{{OssUrl}}/resource/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js"></script>
<script type="text/javascript">
    $(function () {
        var url = ctx + "/system/menu/roleMenuTreeData?roleId=" + $("#roleId").val();
        var options = {
            id: "menuTrees",
            url: url,
            check: {enable: true},
            expandLevel: 0
        };
        $.tree.init(options);
    });

    $("#form-role-edit").validate({
        onkeyup: false,
        rules: {
            roleSort: {
                digits: true
            },
        },
        messages: {
        },
        focusCleanup: true
    });

    function edit() {
        var roleId = $("input[name='roleId']").val();
        var roleName = $("input[name='roleName']").val();
        var roleKey = $("input[name='roleKey']").val();
        var roleSort = $("input[name='roleSort']").val();
        var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
        var remark = $("input[name='remark']").val();
        var menuIds = $.tree.getCheckedNodes();
        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "/system/role/edit",
            data: {
                "roleId": roleId,
                "roleName": roleName,
                "roleKey": roleKey,
                "roleSort": roleSort,
                "status": status,
                "remark": remark,
                "menuIds": menuIds
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }
</script>
</body>
</html>
{{end}}